<?php
include('../../inc/global.inc');
$url=$_SERVER['HTTP_REFERER'];
?>
<?php
if($_POST[tj_act]){
$time1=$_POST[add_year]."-".$_POST[add_month]."-".$_POST[add_day];

$c_rs_1=mysql_query("select * from news_type where id='$_POST[catalog_1]'");
$c_row_1=mysql_fetch_array($c_rs_1);
$c_rs_2=mysql_query("select * from news_type where id='$_POST[catalog_2]'");
$c_row_2=mysql_fetch_array($c_rs_2);
$c_rs_3=mysql_query("select * from news_type where id='$_POST[catalog_3]'");
$c_row_3=mysql_fetch_array($c_rs_3);
$catalog_1=($_POST[catalog_1])?$_POST[catalog_1]:0;
$catalog_2=($_POST[catalog_2])?$_POST[catalog_2]:0;
$catalog_3=($_POST[catalog_3])?$_POST[catalog_3]:0;

$n_sh=$_POST[n_sh]?$_POST[n_sh]:0;
$n_tj=$_POST[n_tj]?$_POST[n_tj]:0;

mysql_query("insert into news (news_title,type_id,type_name,type_id2,type_name2,type_id3,type_name3,news_content,news_time,picture,n_sh,n_tj) values ('$_POST[news_title]','$catalog_1','$c_row_1[type_name]','$catalog_2','$c_row_2[type_name]','$catalog_3','$c_row_3[type_name]','$_POST[news_content]','$time1','$_POST[picture]','$n_sh','$n_tj')");
echo "<script>alert('发布成功');location='index.php';</script>";

}
?>
<?php
if($_POST['xg_act']){
$time1=$_POST[add_year]."-".$_POST[add_month]."-".$_POST[add_day];
$c_rs_1=mysql_query("select * from news_type where id='$_POST[catalog_1]'");
$c_row_1=mysql_fetch_array($c_rs_1);
$c_rs_2=mysql_query("select * from news_type where id='$_POST[catalog_2]'");
$c_row_2=mysql_fetch_array($c_rs_2);
$c_rs_3=mysql_query("select * from news_type where id='$_POST[catalog_3]'");
$c_row_3=mysql_fetch_array($c_rs_3);

$catalog_1=($_POST[catalog_1])?$_POST[catalog_1]:0;
$catalog_2=($_POST[catalog_2])?$_POST[catalog_2]:0;
$catalog_3=($_POST[catalog_3])?$_POST[catalog_3]:0;


$n_sh=$_POST[n_sh]?$_POST[n_sh]:0;
$n_tj=$_POST[n_tj]?$_POST[n_tj]:0;
mysql_query("update news set news_title='$_POST[news_title]',type_id='$catalog_1',type_name='$c_row_1[type_name]',type_id2='$catalog_2',type_name2='$c_row_2[type_name]',type_id3='$catalog_3',type_name3='$c_row_3[type_name]',news_content='$_POST[news_content]',picture='$_POST[picture]',n_sh='$n_sh',n_tj='$n_tj',news_time='$time1' where id='".$_POST['iid']."'");
echo "<script>alert('修改成功');location='".$_POST['urls']."';</script>";
}
?>
<HTML>
<HEAD>
<TITLE>Admin</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<LINK href="../css/css.css" rel=stylesheet>
<script type='text/javascript' src="../js/islogin.js" charset="gb2312"></script>
<BODY>
<center>
<script language = "JavaScript">    
<?php
$rs1=mysql_query("select * from news_type where id<>1 and type_id<>1 order by id asc");
?>
var onecount;
onecount=0;
subcat=new Array();
<?php
$count1=0;
while($row1=mysql_fetch_array($rs1)){?>
subcat[<?=$count1?>]=new Array("<?=$row1[type_name]?>","<?=$row1[type_id]?>","<?=$row1[id]?>");
<?php
$count1=$count1+1;}?>
onecount=<?=$count1?>;  
//联动函数    
function changelocation(locationid){   
   document.form1.catalog_2.length=0;     
   var locationid=locationid;   
   var i;   
   for(i=0;i<onecount;i++){   
       if(i==0){     
          document.form1.catalog_2.options[document.form1.catalog_2.length]=new Option("--二级分类--","");
		  }   
       if(subcat[i][1]==locationid){     
          document.form1.catalog_2.options[document.form1.catalog_2.length]=new Option(subcat[i][0],subcat[i][2]);   
          }                   
    }   
}

function changelocation2(locationid2)   
{   
document.form1.catalog_3.length=0;     
var locationid2=locationid2;   
var i2;   
for (i2=0;i2<onecount;i2++){   
     if(i2==0){     
         document.form1.catalog_3.options[document.form1.catalog_3.length]=new Option("--三级分类--","");     
         }   
     if(subcat[i2][1]==locationid2){     
         document.form1.catalog_3.options[document.form1.catalog_3.length]=new Option(subcat[i2][0],   subcat[i2][2]);   
         }                   
     }   
}
</script>
<table width="90%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
  <tr>
    <td height="25" bgcolor="#EEEEF9" style="padding-left:5px;">信息中心&nbsp;&nbsp;<a href="javascript:history.go(-1)">返回</a></td>
  </tr>
</table>
<?php
if($_GET[tj]){
?>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
<form method="post" action="" onSubmit="return check()" name="form1">
    <tr>
      <td height="30" colspan="3" align="center" bgcolor="#8DA8CF"><strong>发布信息信息</strong></td>
    </tr>
  <tr>
    <td width="23%" height="25" align="center" bgcolor="#8DA8CF">信息主题</td>
    <td width="77%" bgcolor="#FFFFFF" style="padding-left:4px;"><input name="news_title" type="text" size="50"></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">分类</td>
	<td bgcolor="#FFFFFF" style="padding-left:4px;">
<select name="catalog_1" onChange="changelocation(document.form1.catalog_1.options[document.form1.catalog_1.selectedIndex].value)">
<option value="">--一级分类--</option>   
<?php
$rrs=mysql_query("select * from news_type where type_id=0 and id<>1");    
while($rrow=mysql_fetch_array($rrs)){   
?>     
<option value="<?=$rrow[id]?>"><?=$rrow[type_name]?></option>   
 <?php }?></select>-<select name="catalog_2" onFocus="changelocation(document.form1.catalog_1.options[document.form1.catalog_1.selectedIndex].value)">
					  <option value="">--二级分类--</option>
                      </select>-<select name="catalog_3" onFocus="changelocation2(document.form1.catalog_2.options[document.form1.catalog_2.selectedIndex].value)">   
                        <option value="" selected>--三级分类--</option>
                      </select></td>
  </tr>

  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">详细内容</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;"><?php echo fck($value,'news_content');?></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">发布时间</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;"><input name="add_year" type="text" size="3" value="<?=date("Y",time())?>"> - <input name="add_month" type="text" size="2" value="<?=date("m",time())?>"> 
    - <input name="add_day" type="text" size="2" value="<?=date("d",time())?>"></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">上传图片</td>
    <td bgcolor="#FFFFFF" style="padding-left:3px;"><INPUT name="picture" size="28" type="text">&nbsp;<input name="button" type="button" onClick="window.open ('../upfile.php', 'newwindow', 'height=50, width=400, top=250, left=250, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')" value="上传图片"></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">信息设置</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;">是否显示 <input name="n_sh" type="checkbox" value="1" checked>&nbsp;&nbsp;是否推荐 <input name="n_tj" type="checkbox" value="1"></td>
  </tr>
  <tr><input type="hidden" name="tj_act" value="ok">
    <td height="25" colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" value="提交"></td>
    </tr>
  </form>
</table>
<?php }?>
<?php
if($_GET['xg']){
$rs=mysql_query("select * from news where id='".$_GET['xg_id']."'");
$row=mysql_fetch_array($rs);
?>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
<form method="post" action="" name="form1">
    <tr>
      <td height="30" colspan="3" align="center" bgcolor="#8DA8CF"><strong>修改新闻信息</strong></td>
    </tr>
  <tr>
    <td width="23%" height="25" align="center" bgcolor="#8DA8CF">信息主题</td>
    <td width="77%" bgcolor="#FFFFFF" style="padding-left:4px;"><input name="news_title" type="text" size="50" value="<?=$row[news_title]?>"></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">分类</td>
	<td bgcolor="#FFFFFF" style="padding-left:4px;">
<select name="catalog_1" onChange="changelocation(document.form1.catalog_1.options[document.form1.catalog_1.selectedIndex].value)">
<option value="">--一级分类--</option>   
<?php
$rrs=mysql_query("select * from news_type  where type_id=0 and id<>1");    
while($rrow=mysql_fetch_array($rrs)){   
?>     
<option value="<?=$rrow[id]?>" <?php if($row[type_id]==$rrow[id]){echo "selected";}?>><?=$rrow[type_name]?></option>   
 <?php }?></select>-<select name="catalog_2" onFocus="changelocation(document.form1.catalog_1.options[document.form1.catalog_1.selectedIndex].value)">
					  <option value="0">--二级分类--</option>
					  <?php 
					    $rrs2=mysql_query("select * from news_type where id='$row[type_id2]'");
						while($rrow2=mysql_fetch_array($rrs2)){
					  ?><option value="<?=$rrow2['id']?>" selected><?=$rrow2[type_name]?></option>
					  <?php }?>
                      </select>-<select name="catalog_3" onFocus="changelocation2(document.form1.catalog_2.options[document.form1.catalog_2.selectedIndex].value)">   
                        <option   value="0"   selected>--三级分类--</option>
						<?php 
					    $rrs2=mysql_query("select * from news_type where id='$row[type_id3]'");
						while($rrow2=mysql_fetch_array($rrs2)){
					  ?><option value="<?=$rrow2['id']?>" selected><?=$rrow2[type_name]?></option>
					  <?php }?>
                      </select></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#8DA8CF">详细内容</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;"><?php echo fck($row[news_content],'news_content');?></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">发布时间</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;"><input name="add_year" type="text" size="4" value="<?=substr($row[news_time],0,4)?>"> - <input name="add_month" type="text" size="2" value="<?=substr($row[news_time],5,2)?>"> - <input name="add_day" type="text" size="2" value="<?=substr($row[news_time],8,2)?>"></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">上传图片</td>
    <td bgcolor="#FFFFFF" style="padding-left:3px;"><?php if($row[picture]){?><a href="http://www.sandib2b.cn/upfile/<?=$row[picture]?>" target="_blank"><img src="http://www.sandib2b.cn/upfile/<?=$row[picture]?>" border="0" width="120" height="100"></a><br>
<?php }?><INPUT name="picture" size="28" type="text" value="<?=$row[picture]?>">&nbsp;<input name="button" type="button" onClick="window.open ('../upfile.php', 'newwindow', 'height=50, width=400, top=250, left=250, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')" value="上传图片"></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">信息设置</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;">是否显示 <input name="n_sh" type="checkbox" value="1" <?php if($row[n_sh]==1){echo "checked";}?>>&nbsp;&nbsp;是否推荐 <input name="n_tj" type="checkbox" value="1" <?php if($row[n_tj]==1){echo "checked";}?>></td>
  </tr>
  <tr><input type="hidden" name="xg_act" value="ok"><input type="hidden" name="urls" value="<?=$url?>">
  <input type="hidden" name="iid" value="<?=$row['id']?>">
    <td height="25" colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" value="提交"></td>
    </tr>
  </form>
</table>
<?php }?>
</center>
</BODY>
</HTML>

<script language="javascript">
function $(id){
   return document.getElementById(id);
  }
function check(){
  if($("news_title").value==""){
     alert("招标主题不能为空");
     $("news_title").focus();
     return false;
}
if($("catalog_1").value==""){
     alert("分类不能为空");
     $("catalog_1").focus();
     return false;
}
}
</script>